#!/usr/bin/env bash


help(){
    cat<<__EOF__
Usage: m wallpaper [OPTIONS]

Description: Set the desktop wallpaper to the specified image file

Options:
  --help             Show this help message
  --set IMAGE_PATH  Set the wallpaper to the specified image file


Examples:
  m wallpaper --set ~/wallpapers/tree.jpg       # set wallpaper
__EOF__
}

set_wallpaper(){
    osascript -e "tell application \"System Events\" to tell every desktop to set picture to \"${1}\" as POSIX file"
}

case $1 in
    --help)
        help
        ;;
    --set)
        shift
        [ -z "$1" ] && help && exit 1
        set_wallpaper "$1"
        ;;
    *)
        help && exit 1
        ;;
esac
